package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.ReservationDto;
import com.zzyl.service.CustomerReservationService;
import com.zzyl.utils.UserThreadLocal;
import com.zzyl.vo.ReservationVo;
import com.zzyl.vo.SurplusTimeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/customer/reservation")
@Api(tags = "客户预约管理")
public class CustomerReservationController extends BaseController {

    @Autowired
    private CustomerReservationService customerReservationService;

    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public ResponseResult<Integer> getCancelledReservationCount() {
        Long userId = UserThreadLocal.getUserId();

        Integer count =customerReservationService.getCancelledReservationCount(userId);
        return ResponseResult.success(count);
    }

    @GetMapping("/countByTime")
    @ApiOperation("查询预约数量")
    public ResponseResult<List<SurplusTimeVo>> getReservationCountByTime(Long time) {
        List<SurplusTimeVo> surplusTimeVos =customerReservationService.getReservationCountByTime(time);
        return ResponseResult.success(surplusTimeVos);
    }

    @PostMapping
    @ApiOperation("预约")
    public ResponseResult reservation(@RequestBody ReservationDto reservationDto) {
        Long userId = UserThreadLocal.getUserId();
        customerReservationService.add(reservationDto);
        return ResponseResult.success();
    }

    @GetMapping("/page")
    @ApiOperation("分页查询预约记录")
    public ResponseResult<PageResponse<ReservationVo>> page(Integer pageNum, Integer pageSize ,Integer status) {
        Long userId = UserThreadLocal.getUserId();
        PageResponse<ReservationVo> pageResponse = customerReservationService.page(pageNum, pageSize,userId, status);
        return ResponseResult.success(pageResponse);
    }


    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public ResponseResult cancel(@PathVariable("id") Long id) {
        Long userId = UserThreadLocal.getUserId();
        customerReservationService.cancel(id,userId);
        return ResponseResult.success();
    }
}